import { CellRenderer } from "../../../../../fl/controls/listClasses/CellRenderer";
import { AchievementMinorData } from "../data/AchievementMinorData";
import { MsgManager } from "../../../manager/MsgManager";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { AchievementBonusItemsView } from "./AchievementBonusItemsView";
import { AchievementGetBonusButton } from "./AchievementGetBonusButton";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { Global } from "../../../../../com/gengine/global/Global";
import { EAchieveStatus } from "../../../../../Message/Game/EAchieveStatus";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
type int = number;
//class AchievementMinorCellRender
    
    export  class AchievementMinorCellRender extends CellRenderer
    {
        constructor()
        {
            super();
            this.initStyles();
            this.initView();
            this.mouseEnabled = false;
            this.mouseChildren = true;
            this._btnGetBonus.addEventListener(flash.events.MouseEvent.CLICK, this.clickGetBonusHandler);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            this._myData = arg1 as AchievementMinorData;
            this.updateView();
            return;
        }

        protected initStyles(): void
        {
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        protected clickGetBonusHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (flash.utils.getTimer() < this._lastClickTime + this.GetBonuseTimeSpace) 
            {
                return;
            }
            if (this._myData.isEnd) 
            {
                return;
            }
            if (this._myData.isAchievementProcessing) 
            {
                MsgManager.showRollTipsMsg(Language.getString(80260));
                return;
            }
            this._lastClickTime = flash.utils.getTimer();
            Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementGetMinorBonus, this._myData.code));
            return;
        }

        protected setCanGetBonus(): void
        {
            this._txtProgress.visible = false;
            this._txtProgressStatus.visible = false;
            this._iconYiDaCheng.visible = true;
            this._iconYiDaCheng.bitmapData = GlobalClass.getBitmapData(ImagesConst.AchievementYidacheng);
            this._bonusView.unSetTxtChengjiuGray();
            this._btnGetBonus.visible = true;
            this._btnGetBonus.label = Language.getString(80256);
            this._btnGetBonus.enabled = true;
            this._btnGetBonus.mouseEnabled = true;
            if (this._iconYiDaChengRight != null) 
            {
                this._iconYiDaChengRight.visible = false;
            }
            return;
        }

        protected setFinished(): void
        {
            this._txtProgress.visible = false;
            this._txtProgressStatus.visible = false;
            this._iconYiDaCheng.visible = true;
            this._iconYiDaCheng.bitmapData = GlobalClass.getBitmapData(ImagesConst.AchievementYidacheng);
            this._bonusView.setTxtChengjiuGray();
            this._btnGetBonus.visible = false;
            if (this._iconYiDaChengRight == null) 
            {
                this._iconYiDaChengRight = GlobalClass.getBitmap(ImagesConst.AchievementFinished);
                this._iconYiDaChengRight.x = 491;
                this._iconYiDaChengRight.y = 4;
                this.addChild(this._iconYiDaChengRight);
            }
            this._iconYiDaChengRight.visible = true;
            return;
        }

        protected setDoing(): void
        {
            this._txtProgress.visible = true;
            this._txtProgressStatus.visible = true;
            this._iconYiDaCheng.visible = false;
            this._bonusView.setTxtChengjiuGray();
            this._btnGetBonus.visible = true;
            this._btnGetBonus.label = Language.getString(80255);
            this._btnGetBonus.enabled = false;
            this._btnGetBonus.mouseEnabled = false;
            if (this._iconYiDaChengRight != null) 
            {
                this._iconYiDaChengRight.visible = false;
            }
            return;
        }

        protected initView(): void
        {
            var loc1=null;
            this._iconBg = new Object /* flash.display.Bitmap */();
            this._iconBg.x = 17;
            this._iconBg.y = 8;
            this._iconBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.AchievementIconBg);
            this.addChild(this._iconBg);
            this._icon = new Object /* flash.display.Sprite */();
            this._icon.x = 24;
            this._icon.y = 14;
            this._icon.mouseChildren = false;
            this._icon.mouseEnabled = false;
            this._icon.buttonMode = false;
            this.addChild(this._icon);
            this._txtName = ObjCreate.createGTextField("", 80, 8, 150, 20, this, new GTextFormat(null, 14, 65321));
            loc1 = this._txtName.defaultTextFormat;
            loc1.bold = true;
            this._txtName.defaultTextFormat = loc1;
            this._txtName.mouseEnabled = false;
            this._txtDesc = ObjCreate.createGTextField("", 79, 25, 120, 40, this, new GTextFormat(null, 12, 16769792));
            this._txtDesc.multiline = true;
            this._txtDesc.wordWrap = true;
            this._txtDesc.mouseEnabled = false;
            this.setNameDescPlaceNormal();
            this._txtProgress = ObjCreate.createGTextField("", 180, 16, 120, 20, this, new GTextFormat(null, 12, 16187137));
            this._txtProgress.mouseEnabled = false;
            loc1 = this._txtProgress.defaultTextFormat;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._txtProgress.defaultTextFormat = loc1;
            this._txtProgressStatus = ObjCreate.createGTextField("", 180, 31, 120, 20, this, new GTextFormat(null, 12, 16187137));
            this._txtProgressStatus.mouseEnabled = false;
            loc1 = this._txtProgressStatus.defaultTextFormat;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._txtProgressStatus.defaultTextFormat = loc1;
            this._iconYiDaCheng = new Object /* flash.display.Bitmap */();
            this._iconYiDaCheng.x = 205;
            this._iconYiDaCheng.y = 6;
            this.addChild(this._iconYiDaCheng);
            this._txtCode = ObjCreate.createGTextField("", 290, 20, 200, 20, this);
            this._bonusView = new AchievementBonusItemsView();
            this._bonusView.x = 289 + 75;
            this._bonusView.y = 8;
            this.addChild(this._bonusView);
            this._btnGetBonus = new AchievementGetBonusButton(500, 18, this);
            this._btnAdd = ObjCreate.createGButton("", 557, 22, 18, 18, this, "AddBtn");
            this._btnAdd.addEventListener(flash.events.MouseEvent.CLICK, this.clickAddHandler);
            this._btnAdd.toolTipData = Language.getString(80109);
            this._line = ObjCreate.createBg(9, 60, 561, 2, this, ImagesConst.SplitLine);
            return;
        }

        protected clickAddHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementClickShowMinorAchievemntGot, this._myData));
            return;
        }

        protected setNameDescPlaceNormal(): void
        {
            this._txtName.y = 14;
            this._txtDesc.y = 33;
            return;
        }

        protected setNameDescPlaceLong(): void
        {
            this._txtName.y = 10;
            this._txtDesc.y = 26;
            return;
        }

        protected getStrPixNum(arg1: string): int
        {
            var loc1=0;
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                if (arg1.charCodeAt(loc2) > 255) 
                {
                    loc1 = loc1 + 12;
                }
                else 
                {
                    loc1 = loc1 + 6;
                }
                ++loc2;
            }
            return loc1;
        }

        protected updateView(): void
        {
            if (this._myData == null) 
            {
                return;
            }
            LoaderManager.instance.load(this._myData.iconCode.toString() + ".jpg", this.onIconLoaded);
            this._txtName.text = this._myData.name + "(" + this._myData.achievementLevel.toString() + ")";
            this._txtDesc.text = this._myData.desc;
            this._txtProgress.text = this._myData.curValue.toString() + " / " + this._myData.totalValue.toString();
            this._txtProgressStatus.text = Language.getString(80063);
            this._bonusView.data = this._myData.bonusData;
            if (Global.isDebugModle) 
            {
                this._txtCode.text = this._myData.code.toString();
            }
            else 
            {
                this._txtCode.text = "";
            }
            if (this.getStrPixNum(this._myData.desc) >= 120) 
            {
                this.setNameDescPlaceLong();
            }
            else 
            {
                this.setNameDescPlaceNormal();
            }
            if (this._myData.isEnd) 
            {
                this.setFinished();
                return;
            }
            var loc1=this._myData.status;
            switch (loc1) 
            {
                case EAchieveStatus._EAchieveStatusNotCompelete:
                {
                    this.setDoing();
                    break;
                }
                case EAchieveStatus._EAchieveStatusCompelete:
                {
                    this.setCanGetBonus();
                    break;
                }
                case EAchieveStatus._EAchieveStatusHadEnd:
                {
                    this.setFinished();
                    break;
                }
                default:
                {
                    this.setDoing();
                }
            }
            return;
        }

        protected onIconLoaded(arg1: ImageInfo): void
        {
            var loc1=new Object /* flash.display.Bitmap */();
            loc1.bitmapData = arg1.bitmapData;
            loc1.width = 33;
            loc1.height = 34;
            while (this._icon.numChildren > 0) 
            {
                this._icon.removeChildAt(0);
            }
            this._icon.addChild(loc1);
            return;
        }

        protected /* const */GetBonuseTimeSpace: int=800;

        protected /* var */_myData: AchievementMinorData;

        protected /* var */_iconBg: Object /* flash.display.Bitmap */;

        protected /* var */_icon: Object /* flash.display.Sprite */;

        protected /* var */_txtName: GTextFiled;

        protected /* var */_txtDesc: GTextFiled;

        protected /* var */_txtProgress: GTextFiled;

        protected /* var */_txtProgressStatus: GTextFiled;

        protected /* var */_bonusView: AchievementBonusItemsView;

        protected /* var */_btnGetBonus: AchievementGetBonusButton;

        protected /* var */_btnAdd: GButton;

        protected /* var */_line: ScaleBitmap;

        protected /* var */_iconYiDaCheng: Object /* flash.display.Bitmap */;

        protected /* var */_iconYiDaChengRight: Object /* flash.display.Bitmap */;

        protected /* var */_txtCode: GTextFiled;

        protected /* var */_lastClickTime: int=0;
    }
